Methods and apparatuses for thread management of mult-threading

ABSTRACT

Methods and apparatuses for thread management for multi-threading are described herein. In one embodiment, exemplary process includes selecting, during a compilation of code having one or more threads executable in a data processing system, a current thread having a most bottom order, determining resources allocated to one or more child threads spawned from the current thread, and allocating resources for the current thread in consideration of the resources allocated to the current thread&#39;s one or more child threads to avoid resource conflicts between the current thread and its one or more child threads. Other methods and apparatuses are also described.

FIELD

Embodiments of the invention relate to information processing system;and more specifically, to thread management for multi-threading.

BACKGROUND

Memory latency has become the critical bottleneck to achieving highperformance on modern processors. Many large applications today arememory intensive, because their memory access patterns are difficult topredict and their working sets are becoming quite large. Despitecontinued advances in cache design and new developments in prefetchingtechniques, the memory bottleneck problem still persists. This problemworsens when executing pointer-intensive applications, which tend todefy conventional stride-based prefetching techniques.

One solution is to overlap memory stalls in one program with theexecution of useful instructions from another program, thus effectivelyimproving system performance in terms of overall throughput. Improvingthroughput of multitasking workloads on a single processor has been theprimary motivation behind the emerging simultaneous multithreading (SMT)techniques. An SMT processor can issue instructions from multiplehardware contexts, or logical processors (also referred to as hardwarethreads), to the functional units of a super-scalar processor in thesame cycle. SMT achieves higher overall throughput by increasing overallinstruction-level parallelism available to the architecture via theexploitation of the natural parallelism between independent threadsduring each cycle.

SMT can also improve the performance of applications that aremultithreaded. However, SMT does not directly improve the performance,in terms of reducing latency, of single-threaded applications. Since themajority of desktop applications in the traditional PC environment arestill single-threaded, it is important to investigate if and how SRIresources can be exploited to enhance single-threaded code performanceby reducing its latency. In addition, the current compiler typicallycannot automatically allocate resources for the threads it created.

BRIEF DESCRIPTION OF THE DRAWINGS

The invention may best be understood by referring to the followingdescription and accompanying drawings that are used to illustrateembodiments of the invention. In the drawings:

FIG. 1 illustrates a computer system having multi-threading capabilityaccording to one embodiment.

FIG. 2 illustrates a computer system having multi-threading capabilityaccording to an alternative embodiment.

FIG. 3 illustrates a computer system having a compiler capable ofgenerating a helper thread according to one embodiment.

FIG. 4A illustrates a typical symmetric multi-threading process.

FIG. 4B illustrates an asymmetric multi-thread process according to oneembodiment.

FIG. 5 is flow diagram illustrating an exemplary process for executingone or more helper threads according to one embodiment.

FIG. 6 is a block diagram illustrating exemplary software architectureof a multi-threading system according to one embodiment.

FIG. 7 is a flow diagram illustrating an exemplary process forgenerating a helper thread according to one embodiment.

FIG. 8 is a flow diagram illustrating an exemplary process forparallelization analysis according to one embodiment.

FIGS. 9A-9C show pseudo code for an application, a main thread, and ahelper thread according to one embodiment.

FIG. 10 is a block diagram illustrating an exemplary threadconfiguration according to one embodiment.

FIG. 11 is a block diagram illustrating an exemplary pseudo code forallocating resources for the threads according to one embodiment.

FIG. 12 is a block diagram illustrating an exemplary resource datastructure containing resource information for the threads according toone embodiment.

FIG. 13 is a flow diagram illustrating an exemplary process forallocating resources for threads according to one embodiment.

FIGS. 14A-14D show results of a variety benchmark tests usingembodiments of techniques.

DETAILED DESCRIPTION

Methods and apparatuses for compiler-creating helper threads formulti-threading systems are described. According to one embodiment, acompiler, also referred to as AutoHelper, that implements thread-basedprefetching helper threads on a multi-threading system, such as, forexample, the Intel Pentium™ 4 Hyper-Threading systems, available fromIntel Corporation. In one embodiment, the compiler automates thegeneration of helper threads for Hyper-Threading processors. Thetechniques focus at identifying and generating helper threads of minimalsizes that can be executed to achieve timely and effective dataprefetching, while incurring minimal communication overhead. A runtimesystem is also implemented to efficiently manage the helper threads andthe synchronization between threads. Consequently, helper threads areable to issue timely prefetches for the sequential pointer-intensiveapplications.

In addition, hardware resources such as register contexts may be managedfor helper threads within a compiler. Specifically, the register set maybe statically or dynamically partitioned between main thread and helperthreads, and between multiple helper threads. As a result, thelive-in/live-out register copies via memory for threads may be avoidedand the threads may be destroyed at compile-time, when the compiler runsout of resources, or at runtime when infrequent cases of certain mainthread event occurs.

In the following description, numerous specific details are set forth.However, it is understood that embodiments of the invention may bepracticed without these specific details. In other instances, well-knowncircuits, structures and techniques have not been shown in detail inorder not to obscure the understanding of this description.

Some portions of the detailed descriptions which follow are presented interms of algorithms and symbolic representations of operations on databits within a computer memory. These algorithmic descriptions andrepresentations are used by those skilled in the data processing arts tomost effectively convey the substance of their work to others skilled inthe art. An algorithm is here, and generally, conceived to be aself-consistent sequence of operations leading to a desired result. Theoperations are those requiring physical manipulations of physicalquantities. Usually, though not necessarily, these quantities take theform of electrical or magnetic signals capable of being stored,transferred, combined, compared, and otherwise manipulated. It hasproven convenient at times, principally for reasons of common usage, torefer to these signals as bits, values, elements, symbols, characters,terms, numbers, or the like.

It should be borne in mind, however, that all of these and similar termsare to be associated with the appropriate physical quantities and aremerely convenient labels applied to these quantities. Unlessspecifically stated otherwise as apparent from the following discussion,it is appreciated that throughout the description, discussions utilizingterms such as “processing” or “computing” or “calculating” or“determining” or “displaying” or the like, refer to the action andprocesses of a computer system, or similar data processing device, thatmanipulates and transforms data represented as physical (e.g.electronic) quantities within the computer system's registers andmemories into other data similarly represented as physical quantitieswithin the computer system memories or registers or other suchinformation storage, transmission or display devices.

Embodiments of the present invention also relate to apparatuses forperforming the operations described herein. An apparatus may bespecially constructed for the required purposes, or it may comprise ageneral purpose computer selectively activated or reconfigured by acomputer program stored in the computer. Such a computer program may bestored in a computer readable storage medium, such as, but is notlimited to, any type of disk including floppy disks, optical disks,CD-ROMs, and magnetic-optical disks, read-only memories (ROMs), randomaccess memories (RAMs) such as Dynamic RAM (DRAM), erasable programmableROMs (EPROMs), electrically erasable programmable ROMs (EEPROMs),magnetic or optical cards, or any type of media suitable for storingelectronic instructions, and each of the above storage components iscoupled to a computer system bus.

The algorithms and displays presented herein are not inherently relatedto any particular computer or other apparatus. Various general purposesystems may be used with programs in accordance with the teachingsherein, or it may prove convenient to construct more specializedapparatus to perform the methods. The structure for a variety of thesesystems will appear from the description below. In addition, embodimentsof the present invention are not described with reference to anyparticular programming language. It will be appreciated that a varietyof programming languages may be used to implement the teachings of theembodiments of the invention as described herein.

A machine-readable medium includes any mechanism for storing ortransmitting information in a form readable by a machine (e.g., acomputer). For example, a machine-readable medium includes read onlymemory (“ROM”); random access memory (“RAM”); magnetic disk storagemedia; optical storage media; flash memory devices; electrical, optical,acoustical or other form of propagated signals (e.g., carrier waves,infrared signals, digital signals, etc.); etc.

FIG. 1 is a block diagram of an exemplary computer which may be usedwith an embodiment. For example, exemplary system 100 shown in FIG. 1may perform the processes shown in FIGS. 5-8. Exemplary system 100 maybe a multi-threading system, such as an Intel Pentium™ 4 Hyper-Threadingsystem. Exemplary system 100 may be a simultaneous multithreading (SMT)or chip multiprocessing (CMP) enabled system.

Note that while FIG. 1 illustrates various components of a computersystem, it is not intended to represent any particular architecture ormanner of interconnecting the components, as such details are notgermane to the present invention. It will also be appreciated thatnetwork computers, handheld computers, cell phones, and other dataprocessing systems which have fewer components or perhaps morecomponents may also be used with the present invention.

As shown in FIG. 1, the computer system 100, which is a form of a dataprocessing system, includes a bus 102 which is coupled to amicroprocessor 103 and a ROM 107, a volatile RAM 105, and a non-volatilememory 106. The microprocessor 103, which may be a Pentium processorfrom Intel Corporation or a PowerPC processor from Motorola, Inc., iscoupled to cache memory 104 as shown in the example of FIG. 1. The bus102 interconnects these various components together and alsointerconnects these components 103, 107, 105, and 106 to a displaycontroller and display device 108, as well as to input/output (I/O)devices 110, which may be mice, keyboards, modems, network interfaces,printers, and other devices which are well-known in the art. Typically,the input/output devices 110 are coupled to the system throughinput/output controllers 109. The volatile RAM 105 is typicallyimplemented as dynamic RAM (DRAM) which requires power continuously inorder to refresh or maintain the data in the memory. The non-volatilememory 106 is typically a magnetic hard drive, a magnetic optical drive,an optical drive, or a DVD RAM or other type of memory system whichmaintains data even after power is removed from the system. Typicallythe non-volatile memory will also be a random access memory, althoughthis is not required. While FIG. 1 shows that the non-volatile memory isa local device coupled directly to the rest of the components in thedata processing system, it will be appreciated that the presentinvention may utilize a non-volatile memory which is remote from thesystem, such as a network storage device which is coupled to the dataprocessing system through a network interface such as a modem orEthernet interface. The bus 102 may include one or more buses connectedto each other through various bridges, controllers, and/or adapters, asis well-known in the art. In one embodiment, the I/O controller 109includes a USB (Universal Serial Bus) adapter for controlling USBperipherals or a PCI controller for controlling PCI devices, which maybe included in IO devices 110. In a further embodiment, I/O controller109 includes an IEEE-1394 controller for controlling IEEE-1394 devices,also known as FireWire devices.

According to one embodiment, processor 103 may include one or morelogical hardware contexts, also referred to as logical processors, forhandling multiple threads simultaneously, including a main thread, alsoreferred to as a non-speculative thread, and one or more helper threads,also referred to as speculative threads, of an application. Processor103 may be a Hyper Threading processor, such as a Pentium 4 or a Xeonprocessor capable of performing multithreading processes from IntelCorporation. During an execution of an application, the main thread andone or more helper threads are executed in parallel. The helper threadsare speculatively executed associated with, but somewhat independent to,the main thread to perform some precomputations, such as speculativeprefetches of addresses or data, for the main thread to reduce thememory latency incurred by the main thread.

According to one embodiment, the code of the helper threads (e.g., thesource code and the binary executable code) are generated by a compiler,such as AutoHelper compiler available from Intel Corporation, loaded andexecuted in a memory, such as volatile RAM 105, by an operating system(OS) executed by a processor, such as processor 103. The operatingsystem running within the exemplary system 100 may be a Windowsoperating system from Microsoft Corporation or a Mac OS from AppleComputer. Alternatively, the operating system may be a Linux or Unixoperating system. Other operating systems, such as embedded real-timeoperating systems, may be utilized.

Current Hyper-Threading processors typically provide two hardwarecontexts, or logical processors. To improve the performance of asingle-threaded application, Hyper-Threading technology can utilize itssecond context to perform prefetching for the main thread. Having aseparate context allows the helper threads' execution to be decoupledfrom the control flow of the main thread, unlike software prefetching.By running far ahead of the main thread to perform long-rangeprefetches, the helper threads can trigger prefetches early, andeliminate or reduce the cache miss penalties experienced by the mainthread.

With AutoHelper, a compiler is able to automatically generateprefetching helper threads for Hyper-Threading machines. The helperthreads aim at bringing the latency-hiding benefit of multithreading tosequential workloads. Unlike threads produced by the conventionalparallelizing compilers, the helper threads only prefetch for the mainthread, which does not reuse the computed results from the helperthreads. According to on embodiment, the program correctness is stillmaintained by the main thread's execution, while the helper threads donot affect program correctness and are used solely for performanceimprovement. This attribute permits the use of more aggressive forms ofoptimization in generating helper threads. For example, when the mainthread does not need help, certain optimizations may be performed, whichare not possible with conventional throughput threading paradigm.

In one embodiment, if it is predicted that a helper is not needed for acertain period of time, the helper may terminate and release all theresources associate with the helper to main thread. According to anotherembodiment, if it is predicted that a helper may be needed shortly, thehelper may be in a pause mode, which still consumes some resources onHyper-Threading hardware. Exponential back-off (via halting) will beinvoked if the helper stays in the pause mode too long (e.g., exceedinga programmable timeout period). According to a further embodiment, ifthe compiler cannot predict when the helper thread will be needed, thehelper may be in a snooze mode and may relinquish the occupied processorresources to the main thread.

Furthermore, according to one embodiment, performance monitoring andon-the-fly adjustments are made possible under helper-threadingparadigm, because the helper thread does not contribute to the semanticsof the main program. When a main thread needs a helper, it will wake upthe main thread. For example, with respect to a run-away helper or arun-behind thread, one of the processes described above may be invokedto adjust the run-away helper thread.

FIG. 2 is a block diagram illustrating one embodiment of a computingsystem 200 capable of performing the disclosed techniques. In oneembodiment, the computing system 200 includes a processor 204 and amemory 202. Memory 202 may store instructions 210 and data 212 forcontrolling the operation of the processor 204. The processor 204 mayinclude a front end 221 that supplies instruction information to anexecution core 230. The front end 221 may supply the instructioninformation to the processor core 204 in program order.

For at least one embodiment, the front end 221 includes a fetch/decodeunit 222 that includes logically independent sequencers 220 for each ofa plurality of thread contexts. The logically independent sequencer(s)220 may include marking logic 280 to mark the instruction informationfor speculative threads as being “speculative.” One skilled in the artwill recognize that, for an embodiment implemented in a multipleprocessor multithreading environment, only one sequencer 220 may beincluded in the fetch/decode unit 222.

As used herein, the term “instruction information” is meant to refer toinstructions that can be understood and executed by the execution core230. Instruction information may be stored in a cache 225. The cache 225may be implemented as an execution instruction cache or an executiontrace cache. For embodiments that utilize an execution instructioncache, “instruction information” includes instructions that have beenfetched from an instruction cache and decoded. For embodiments thatutilize a trace cache, the term “instruction information” includestraces of decoded micro-operations. For embodiments that utilize neitheran execution instruction cache nor trace cache, “instructioninformation” also includes raw bytes for instructions that may store inan instruction cache such as I cache 244.

FIG. 3 is a block diagram illustrating an exemplary system containing acompiler to generate one or more helper threads according to oneembodiment. Referring to FIG. 3, exemplary processing system 300includes a memory system 302 and a processor 304. Memory system 302 maystore instructions 310 and data 312 for controlling the operation of theprocessor 304. For example, instructions 310 may include a compilerprogram 308 that, when executed, causes the processor 304 to compile aprogram that resides in the memory system 302. Memory 302 holds theprogram to be compiled, intermediate forms of the program, and aresulting compiled program. For at least one embodiment, the compilerprogram 308 includes instructions to generate code for one or morehelper threads with respect to a main thread.

Memory system 302 is intended as a generalized representation of memoryand may include a variety of forms of memory, such as a hard drive,CD-ROM, random access memory (RAM), dynamic random access memory (DRAM),static random access memory (SRAM) and related circuitry. Memory system302 may store instructions 310 and/or data 312 represented by datasignals that may be executed by processor 304. The instructions 310and/or data 312 may include code for performing any or all of thetechniques discussed herein.

Specifically, compiler 308 may include a delinquent load identifier 320that, when executed by the processor 304, identifies one or moredelinquent load regions of a main thread. The compiler 308 may alsoinclude a parallelization analyzer 324 that, when executed by theprocessor 304, performs one or more parallelization analysis for thehelper threads. Also, the compiler 308 may include a slicer 322 thatidentifies one or more slices to be executed by a helper thread in orderto perform speculative precomputation. The compiler 308 may furtherinclude a code generator 328 that, when executed by the processor 304,generates the code (e.g., source and executable code) for the helperthreads.

Executing helper threads in an SMT machine is a form of asymmetricmultithreading, as shown in FIG. 4B according to one embodiment.Traditional parallel programming models provide symmetricmultithreading, as shown in FIG. 4A. In contrast, the helper threads,such as helper threads 451-454 in FIG. 4B execute as user-level threads(fibers) with lightweight thread invocation and switching. Furthermore,symmetric multithreading requires well-tuned data decomposition acrosssymmetric threads, such as threads 401-404 in FIG. 4A. In the helperthread model, according to one embodiment, the main thread runs thesequential code that operates on the entire data set, without incurringdata decomposition overhead. Without decomposing the data, the compilerinstead focuses on providing multiple helpers for timely prefetches forthe main thread's data.

FIG. 5 is a flow diagram illustrating an exemplary process for executinga helper thread according to one embodiment. Exemplary process 500 maybe performed by a processing logic that may comprise hardware(circuitry, dedicated logic, etc.), software (such as is run on ageneral purpose computer system or a dedicated machine), or acombination of both. In one embodiment, exemplary process 500 includesexecuting a main thread of an application in a multi-threading system,and spawning one or more helper threads from the main thread to performone or more computations for the main thread when the main thread entersa region having one or more delinquent loads, code of the one or morehelper thread being created during a compilation of the main thread.

Referring to FIG. 5, at block 501, the processing logic creates aninternal thread pool to maintain a list of logical thread contexts whichmay be used by one or more helper threads. At block 502, a new threadteam may be created before a main thread enters a delinquent load region(e.g., precomputation region) which may be identified by a compiler. Inone embodiment, the new thread team initially contains only the callingthread. According to one embodiment, the compiler may insert astatement, such as start_helper statement, before the main thread entersthe region to activate one or more helper threads. At block 503, whenthe main thread enters the region, the main thread spawns (via afunction call, such as invoke_helper) one or more helper threads whichare created using the resources from the thread pool to perform one ormore precomputations, such as prefetching addresses and data, for themain thread. According to one embodiment, if no logical processor isavailable for executing the spawned helper threads, the helper threadsmay be created and placed in a run queue for the thread team forsubsequent execution. In one embodiment, the run queue may be associatedwith a time-out. The request to invoke a helper is simply dropped (e.g.,terminated) after the time-out period expires, assuming that theprefetch will no longer be timely. This is different from traditionaltask-queue model for parallel programming, where each task needs to beexecuted.

At block 504, at least a portion of the code within the region of themain thread is executed using in part the data (e.g., prefetched orprecomputed) provided by the one or more helper threads. According toone embodiment, the results computed by a helper thread are notintegrated into the main thread. The benefit of a helper thread lies inits side effects of prefetching, not in reusing its computation results.This allows the compiler to aggressively optimize the code generationfor helper threads. The main thread handles the correctness issue, whilethe helper threads target the performance of a program. This also allowsthe helper thread invoking statement, such as invoke_helper, to droprequests whenever deemed appropriate. Finally, non-faultinginstructions, such as the prefetch instructions, may be used to avoiddisruptions to the main thread if exceptions are signaled in a helperthread.

At block 505, the one or more helper threads associated with the mainthread are terminated (via a function call, such as finish_helper) whenthe main thread is about to exit the delinquent load region and theresources, such as logical thread contexts, associated with theterminated helper threads are released back to the thread pool. Thisenables future requests to immediately recycle the logical threadcontexts from the thread pool. Other operations apparent to those withordinary skill in the art may be included.

Hyper-Threading technology is well suited for supporting the executionof one or more helper threads. According to one embodiment, in eachprocessor cycle, instructions from either of the logical processors canbe scheduled and executed simultaneously on shared execution resources.This allows helper threads to issue timely prefetches. In addition, theentire on-chip cache hierarchy is shared between the logical processors,which is useful for helper threads to effectively prefetch for the mainthread at all levels of the cache hierarchy. Furthermore, although thephysical execution resources are shared between the logical processors,the architecture state is duplicated in a Hyper-Threading processor. Theexecution of helper threads will not alter the architecture state in thelogical processor executing the main thread.

However, on Hyper-Threading technology enabled machines, helper threadscan still impact the execution of main thread due to the writes tomemory. Because helper threads share memory with the main thread, theexecution of helper threads should be guaranteed not to write to thedata structures of the main thread. In one embodiment, the compiler(e.g., AutoHelper) provides memory protection between the main threadand the helper threads. The compiler removes stores to non-localvariables in the helper threads.

FIG. 6 is a block diagram illustrating an exemplary architecture of acompiler according to one embodiment. In one embodiment, exemplaryarchitecture 600 includes, among others, a front end module 601,profiler 602, interprocedural analysis and optimization module 603,compiler 604, global scalar optimization module 605, and backend module606. In one embodiment, front end module 601 provides a commonintermediate representation, such as IL0 representation from IntelCorporation, for source codes written in a variety of programminglanguages, such as C/C++ and Fortran. As a result, the compiler, such asAutoHelper 604 is applicable irrespective of the source languages and ofthe target platforms. Profiler 602 performs a profiling run to examinethe characteristics of the representation. Interprocedural analysismodule 603 may exposes optimization opportunities across procedure callboundaries. Thereafter, the compiler 604 (e.g., AutoHelper) is invokedto generate code for one or more helper threads. Global scalaroptimization module 605 applies, using partial redundancy elimination tominimize the number of times an expression is evaluated. Finally,backend module 606 generates binary code for the helper threads for avariety of platforms, such as IA-32 or Itanium platform from IntelCorporation. Other components apparent to those with ordinary skill inthe art may be included.

Unlike a conventional approach, AutoHelper (e.g., the compiler)eliminates the profile-instrumentation pass to make the tool easier touse. According to one embodiment, the compiler can directly analyze theoutput from profiling results, such as those generated by Intel's VTune™Performance Analyzer, which is enabled for Hyper-Threading technology.Because it is a middle-end pass instead of a post-pass tool, thecompiler is able to utilize several product-quality analyses, such asarray dependence analysis and global scalar optimization, etc. Theseanalyses, invoked after the compiler, perform aggressive optimizationson the helper threads' code.

According to one embodiment, the compiler generates one or more helperthreads to precompute and prefetch the address accessed by a load thatmisses the cache frequently, also referred to as a delinquent load. Thecompiler also generates one or more triggers in the main thread thatspawns one or more helper threads. The compiler implements the triggeras an invoking function, such as the invoke_helper function call. Oncethe trigger is reached, the load is expected to appear later in theinstruction stream of the main thread, hence the speculatively executedhelper threads can reduce the number of cache misses in the main thread.

FIG. 7 is flow diagram illustrating an exemplary process performed by acompiler, such as AutoHelper, according to one embodiment. Exemplaryprocess 700 may be performed by a processing logic that may comprisehardware (circuitry, dedicated logic, etc.), software (such as is run ona general purpose computer system or a dedicated machine), or acombination of both. In one embodiment, exemplary process 700 starts atblock 701, to identifying delinquent loads using, for example, the VTunetool from Intel Corporation, to perform parallelization analysis forhelper threads (block 702), to generate code for helper threads (block703), and to allocate resources, such as hardware registers or memoriesfor each helper threads and the main thread (block 704), which will bedescribed in details further below.

According to one embodiment, the compiler identifies the most delinquentloads in an application source code using one or more run-time profiles.Traditional compilers collect the profiles in two steps:profile-instrumentation and profile-generation. However, because cachemiss is not an architecture feature that is exposed to the compilers,profile-instrumentation pass does not permit instrumentation of cachemisses for the compiler to identify delinquent loads. The profiles foreach cache hierarchy are collected via a utility, such as the VTune™Analyzer from Intel Corporation. In one embodiment, the application maybe executed with debugging information in a separate profiling run priorto the compiler. During the profiling run, cache misses are sampled andthe hardware counters are accumulated for each static load in theapplication.

The compiler identifies the candidates for thread-based prefetching. Ina particular embodiment, the VTune™ summarizes the cache behavior on aper-load basis. Because the binary for the profiling run is compiledwith the debug information (e.g., debug symbols), it is possible tocorrelate the profiles back to source line numbers and the statements.Certain loads that contribute more than a predetermined threshold may beidentified as delinquent loads. In a particular embodiment, the toploads that contribute to 90% of cache misses are denoted as delinquentloads.

In addition to identifying delinquent load instructions, the compilergenerates helper threads that compute the addresses of delinquent loadsaccurately. In one embodiment, separate code for helper threads isgenerated. The separation between the main thread and the helperthread's code prevents transformations on a helper thread's code fromaffecting the main thread. In one embodiment, the compiler usesmulti-entry threading, instead of conventional out-lining, in the Intelproduct compiler to generate separate codes for helper threads.

Furthermore, according to one embodiment, the compiler performsmulti-entry threading at the granularity of a compiler-selected coderegion, denoted as precomputation region. This region encompasses a setof delinquent loads and defines the scope for speculativeprecomputation. In one embodiment, the implementation usually targetsloop regions, because loops are usually the hot spots in programexecution, and the delinquent loads are the loads that were executedmany times, usually in a loop.

FIG. 8 is flow diagram illustrating an exemplary process forparallelization analysis according to one embodiment. Exemplary process800 may be performed by a processing logic that may comprise hardware(circuitry, dedicated logic, etc.), software (such as is run on ageneral purpose computer system or a dedicated machine), or acombination of both. Referring to FIG. 8, at block 801, the processinglogic builds a dependent graph that captures both data and controldependencies of the main thread. According to one embodiment, in orderto filter out unrelated code and thus reduce the size of a helperthread's code, the compiler first builds a graph that captures both dataand control dependences. The effectiveness and legality of filteringrely on the compiler's ability to accurately disambiguate memoryreferences. As a result, a memory disambiguation module in the compileris invoked to disambiguate pointers to dynamically allocated objects.Because a pointer could be a global variable or a function parameter,the points-to analysis performed by the compiler is interprocedural, ifthe compiler compiles in the whole-program mode. In one embodiment, inorder to build the dependence graph more accurately, a series of arraydependence tests may be performed, so that each element in an array isdisambiguated in building the dependence graph, if all the arrayaccesses are finite expressions. Otherwise, approximation is used.Furthermore, each field in a structure may be disambiguated.

Referring back to FIG. 8, at block 802, the processing logic performs aslicing operation on the main thread using the dependent graph. Duringslicing, according to one embodiment, the compiler first identifies theload addresses of delinquent loads as slice criteria, which specify theintermediate slicing results. After building the dependence graph, thecompiler computes the program slices of the identified slice criteria.The program slices of the slice criteria are defined as the set ofinstructions that contribute to the computation of the addresses formemory prefetches executed by the one or more helper threads. Slicingcan reduce the code to only the instructions relevant to the computationof an address, thus allows the helper threads to run quicker and aheadof the main thread. The compiler only needs to copy instructions in aslice to the helper thread's code.

According to one embodiment, slicing in the compiler extracts a minimalsequence of instructions to produce the addresses of delinquent loads bytransitively traversing the dependence edges backwards. The leaf nodeson the dependence graph of the resulting slices can be converted toprefetch instructions, because no further instructions are dependent onthose leaf nodes. Those prefetch instructions executed by a processor,such as the Pentium™ 4 from Intel Corporation, are both non-blocking andnon-faulting. Different prefetch instructions exist for bringing datainto different levels of cache in the memory hierarchy.

According to one embodiment, slicing operations may be performed withrespect to a given code region. Traversal on the dependence graph in agiven region must terminate when it reaches code outside of that region.Thus, slicing must be terminated during traversal instead of aftertraversal, because the graph traversal may span to the outside of aregion and then back to the inside of a region. Simply collecting theslices according to regions after the traversal may lose precision.

In a further embodiment, the compiler slices each delinquent loadsinstruction one by one. To minimize the duplication of code in helperthreads and reduce the overhead of thread invocation andsynchronization, the compiler merges slices into one helper thread ifthey are in the same precomputation region.

Referring back to FIG. 8, at block 803, the processing logic performsscheduling across the threads to overlap multiple prefetches. In oneembodiment, since Hyper-Threading processors support out-of-orderexecution with large scheduling windows, the processors can look forindependent instructions beyond the current executing instruction whenit waits on a pending cache miss. This aspect of out-of-order executioncan provide substantial performance gain over an in-order processor andreduce the need for chaining speculative precomputation. Furthermore,the compiler selects basic speculative precomputation forHyper-Threading processors. Namely, only one helper thread is scheduledat a time to save the thread spawning and communication overhead.Another benefit from using basic speculative precomputation is that itdoes not inundate the memory system on our Hyper-Threading processors asfast as chaining speculative precomputation does. When the out-of-orderprocessor looks for independent instructions for execution, thoseinstructions can generate too many load requests and saturate the memorysystem. When the helper threads issue prefetching requests, a largenumber of outstanding misses could rapidly fill up the miss buffer and,as a result, stall the processor. Thus, the compiler needs to bejudicious in spawning helper threads. Finally, to ensure timelyprefetching, the compiler pins down the single helper thread and themain thread on respective logical processors.

Referring back to FIG. 8, at block 804, processing logic selects acommunication scheme for the threads. In one embodiment, the compilerprovides a module that computes live-ness information for any givenslice, or any subset of program. Liveness information provides estimateson the communication cost. The information is used to select theprecomputation region that provides good trade-off between communicationand computation. The liveness information may help find triggers or thepoints at which the backward slicing ends.

Because the typical Hyper-Threading processors issue three micro-ops perprocessor cycle and use some hard-partitioned resources, the compilerhas to be judicious as not to let helper threads slow down the mainthread's execution, especially if the main thread issues three micro-opsfor execution per cycle already. For the loop nest encompassingdelinquent loads, the compiler makes trade-off between re-computationand communication in choosing the loop level for performing speculativeprecomputation. For each loop level, starting from the innermost one,according to one embodiment, the compiler selects one of thecommunication-based scheme and computation-based scheme.

According to one embodiment, the communication-based scheme communicatesthe live-in values from the main thread to the helper thread in eachiteration, so the helper thread does not need to re-compute the live-invalues. The compiler will select this scheme if there exists an innerloop encompassing most delinquent loads and if slicing for the innerloop significantly decreases the size of a helper thread. However, thisscheme will be disabled if the communication cost for the inner looplevel is very large. The compiler will give smaller estimate ofcommunication cost, if the live-in values are computed early and thenumber of live-ins is small.

Communication-based scheme will create multiple communication pointsbetween the main thread and its helper thread at runtime.Communication-based scheme is important for Hyper-Threading processors,because relying on only one communication point by re-computing theslice in the helper thread may create too much resource contentionbetween threads. This scheme is similar to constructing a do-across loopin that the main thread initiates the next iteration after it finishescomputing the live-in values for that iteration. The scheme tradescommunication for less computation.

According to one embodiment, the computation-based scheme assumes onlyone communication point between two threads to pass in the live-invalues in the beginning. Afterwards, the helper thread needs to computeeverything it needs to generate accurate prefetch addresses. Thecompiler will select this scheme if there is no inner loop, or ifslicing for this loop level does not significantly increases the size ofa helper thread. Computation-based scheme gives the helper thread moreindependence in execution, once the single communication point isreached.

According to one embodiment, to select the loop level for speculativeprecomputation, the compiler selects the outermost loop that benefitsfrom communication-based scheme. Hence the scheme-selection algorithmdescribed above can terminate once it finds a loop withcommunication-based scheme. If the compiler does not find any loop withcommunication-based scheme, the outermost loop will be the targetedregion for speculative precomputation. After the compiler selects theprecomputation regions and their communication schemes, locating goodtrigger points in the main thread would ensure timely prefetches, whileminimizing the communication between the main thread and the helperthreads. Liveness information helps locate triggers, which are thepoints at which the backward slicing ends. Slicing beyond theprecomputation region ends when the number of live-ins increases.

Referring back to FIG. 8, at block 805, the processing logic determinesa synchronization period for the threads to synchronize with each otherduring the execution. According to one embodiment, the synchronizationperiod is used to express the distance between a helper thread and themain thread. Typically, the helper thread performs all of itsprecomputation in units of synchronization period. This both minimizescommunication and limits the possibility of producing run-away helpers.Because the compiler computes the value of synchronization period andgenerates synchronization code accordingly, special hardware support,such as Outstanding Slice Counter, is no longer needed.

If the synchronization period is too large, the prefetch induced by thehelper thread could not only displace temporally important data to beused by the main thread but also potentially displace earlier prefetcheddata that have not been used by the main thread. On the other hand, ifthe synchronization period is too small, the prefetch could be too lateto be useful. To decide on the value of synchronization period,according to one embodiment, the compiler first computes the differencebetween the length of the slice and the length of program schedule inthe main thread. If the difference is small, the run-ahead distanceinduced by the helper thread in one iteration is consequently small.Multiple iterations may be needed by the helper thread to maintainenough run-ahead distance. Hence, the compiler increases thesynchronization period if the difference is small, and vice versa.

Thereafter, the compiler generates code for the main thread and thehelper thread during a code generation stage. During the code generationstage, the compiler builds a thread graph as the interface between theanalysis phase and code generation phase. Each graph node denotes asequence of instructions, or a code region. The invocation edge betweenthe nodes denotes the thread-spawning relationship, which is importantfor specifying chaining helper threads. Having a thread graph enablescode reuse because, according to one embodiment, the compiler alsoallows the user to insert pragmas in the source program to specify thecode for helper threads and the live-ins. Both the pragma-based approachand the automatic approach share the same graph abstraction. As aresult, the helper thread code generation module may be shared.

The helper thread code generation leverages multi-entry threadingtechnology in the compiler to generate helper thread code. In contrastto the conventional, well-known outlining, the compiler does not createa separate compilation unit (or routine) for the helper thread. Instead,the compiler generates a threaded entry and a threaded return for in thehelper thread code. The compiler keeps all newly generated helper threadcodes intact or inlined within the same user-defined routine withoutsplitting them into independent subroutines. This method provides latercompiler optimizations with more opportunities for performingoptimization on the newly generated helper threads. Fewer instructionsin the helper thread means less resource contention on a hyper-threadedprocessor. This demonstrates that using helper threads for hidinglatency incurs fewer instructions and less resource contention than thetraditional symmetric multithreading model, which is importantespecially because the hyper-threaded processor issues three micro-opsper processor cycle and has some hard-partitioned resources.

According to one embodiment, the generated codes for helper threads willbe re-ordered and optimized by the later on phases in the compiler suchas partial dead-store elimination (PDSE), partial redundancy elimination(PRE), and other scalar optimizations. In that sense, the helper threadcode needs to be optimized to minimize the resource contention. due tothe helper thread. However, those further optimizations may removeprefetching code as well. Therefore, the leaf delinquent loads may beconverted to the volatile-assign statements in the compiler. The leafnode in the dependence graph of a slice implies that no furtherinstructions in the helper thread depend on the loaded value. Hence, thedestination of the volatile-assign statement is changed to a registertemp in the representation to speed up the resulting code. Usingvolatile-assign may prevent all later on compiler global optimizationsfrom removing generated prefetches for delinquent loads.

According to one embodiment, the compiler aims at ensuring the helperthread to run neither too far ahead nor behind the main thread using aself-counting mechanism. According to one embodiment, value X is pre-setfor run-ahead distance control. The X can be modified through a compilerswitch by users, or based on program analysis of the length of slice (orhelper code) and the length of main code. In one embodiment, thecompiler generates mc (M-counter) with an initial value X for mainthread and hc (H-counter) with an initial value 0 for helper thread, andthe compiler generates the counter M and H for counting the sync-upperiods in main and helper code. The idea is that the all four counters(mc, M, hc, H) perform self-counting. The helper thread has no inferenceto main thread. If the helper thread runs too far ahead of main thread,it will issue a wait, if the helper thread runs behind main thread, itwill perform a catch-up.

In a particular embodiment, for every X loop-iterations, the main threadissues a post to ensure that the helper is not waiting and can go aheadto perform non_faulting_load. At this point, if the helper thread waitsfor the main thread after issuing a number of non_faulting_loads inchunks of sync-up period, it will wake up to perform non_faulting_loads.In another particular embodiment, for every X loop-iterations, thehelper thread examines whether its hc counter is greater main thread'smc counter and the hc counter is greater a sync-up period H*X of thehelper thread, if so, the helper will issue a wait and go to sleep. Thisprevents the helper thread from running too far ahead of the mainthread. In a further embodiment, before iterating over another chunk ofsync-up period, the helper thread examines whether its hc counter issmaller than the main thread's mc counter. If so, the helper thread hasfallen behind, and must “catch-up and jump ahead” by updating itscounter hc and H and all capture private and live-in variable from themain thread. FIGS. 9A-9C are diagrams illustrating exemplary pseudo codeof an application, a main thread, and a helper thread according to oneembodiment. Referring to FIGS. 9A-9C, the compiler compiles a sourcecode 901 of an application and generates code for a main thread 902 anda helper thread 903 using at least one of the aforementioned techniques.It will be appreciated that the code 901-903 are not limited to C/C++.Other programming languages, such as Fortran or Assembly, may be used.

After the code for the helper threads have been created, the compilermay further allocate, statically or dynamically, resources for eachhelper thread and the main thread to ensure that there is no resourceconflict between the main thread and the helper threads, and among thehelper threads. Hardware resources, such as register contexts, may bemanaged for helper threads within the compiler. Specifically, theregister set may be statically or dynamically partitioned between themain thread and the helper threads, and between multiple helper threads.As a result, the live-in/live-out register copies via memory for threadsmay be avoided and the threads may be destroyed at compile-time, whenthe compiler runs out of resources, or at runtime when infrequent casesof certain main thread event occurs.

According to one embodiment, the compiler may “walk through” the helperthreads in a bottom-up order and communicates the resource utilizationin a data structure, such as a resource table shown in FIG. 12. Theparent helper thread, which may be the main thread, utilizes thisinformation and ensures that its resources don't overlap with the threadresources. When the thread resources penalize the main execution thread,for example by forcing the main thread to spill/fill registers, thecompiler can kill previously created threads.

FIG. 10 is a block diagram illustrating an exemplary configuration ofthreads according to one embodiment. In this embodiment, exemplaryconfiguration 1000 includes a main thread 1001 (e.g., a parent thread)and three helper threads (e.g., child threads) 1002-1004, which may bespawned from the main thread 1001, while thread 1003 may be spawned fromthread 1002 (e.g., helper thread 1002 is a parent thread of helperthread 1003). It will be appreciated that the helper threads are notlimited to three helper threads, more or less helper threads may beincluded. The helper threads may be spawned by a spawn instruction andthe thread execution may resumes after the spawn instruction.

The threads are created by the compiler during a thread creation phase,such as those operations shown in FIGS. 5-8. According to oneembodiment, the compiler creates the threads in the thread creationphase and allocates resources for the threads in a subsequent threadresource allocation phase. Dynamically and typically, a helper thread isspawned when its parent thread stalls. Exemplary configuration 1000 mayhappen during a page fault or a level 3 (L3) cache miss.

It is crucial that a thread can only share incoming registers (orresources in general) with a parent thread. For example, referring toFIG. 10, when main thread 1001 needs a register, it writes a value toregister RIO before it spawns helper thread 1002 and uses register R10after the helper thread 1002 terminates. Neither the helper thread 1002nor any of its children (in the example, helper thread 1003 is the onlychildren of helper thread 1002, and helper threads 1002 and 1004 arechildren of the main thread 1001) can write to register R10. Otherwisethey would destroy the value in the main thread 1001. This would resultin incorrect program execution. To avoid this resource conflict,according to one embodiment, the compiler may partition the resourcesstatically or dynamically.

According to one embodiment, the compiler allocates resources for thehelper threads and the main thread in a bottom-up order. FIG. 11 is ablock diagram illustrating an exemplary pseudo code for allocatingresources for the threads according to one embodiment. That is, in theexemplary algorithm 1100, the compiler allocates all resources for thehelper threads in a bottom-up order (block 1101) and thereafterallocates resources for the main thread (block 1102) based on theresources used by the helper threads to avoid resource conflicts.

For the purposes of illustration, the resources used the threads areassumed to be the hardware registers. However, similar concepts may beapplied to other resources apparent to one with ordinary skill in theart, such as memory or interrupt. Referring to FIG. 10, the compilerpartitions the registers dynamically by walking bottom up from the leadthread of a thread chain. In this example, helper thread 1003 is a leafthread in the first thread chain including helper thread 1002. Helperthread 1004 is a leaf thread in the second thread chain. The compilerrecords the register allocation in each helper thread in a datastructure, such as a resource table similar to the exemplary resourcetable 1200 of FIG. 12. Then the parent thread reads the resourceallocation of its children thread and does its allocation and reports itin its resource table.

FIG. 12 is a block diagram illustrating an exemplary resource datastructure according to one embodiment. Exemplary data structure 1200 maybe implemented as a table stored in a memory and accessible by acompiler. Alternatively, exemplary data structure 1200 may beimplemented in a database. In one embodiment, exemplary data structure1200 includes, but not limited to, written resources 1202 and live-inresources used by the respective thread identified via thread ID 1201.Other configurations may exist.

Referring to FIGS. 10 and 12, according to one embodiment, at thebeginning, the registers of helper thread 1003 (e.g., the thread havingthe most bottom order in a bottom-up scheme) are allocated. The live-invalues are V5 and V6 and assuming they are assigned to registers R2 andR3 respectively. Also, V7 gets register R4 assigned and V9 gets registerR5 assigned. The resource table for helper thread 1003 includeslive-in=((V5, R2), (V6, R3)) and register written=(R4, R5), as shown inFIG. 12. In helper thread 1002, the compiler replaces V5 with R2 and V6with R3 during the allocation and marks register R4 and R5 (written inhelper thread 1003) as live at the spawn instruction. This preventsregister usage of R4 or R5 across the spawn point of helper thread 1003and thus prevents a resource conflict between helper thread 1002 andhelper thread 1003. For helper thread 1002, the live-in values are V3and V4 and are assigned to register R6 and R7 respectively. When V8 andV20 are assigned to registers R8 and R9 respectively, the resource tablefor helper thread 1002 includes live_in=((V3, R6), (V4, R7)) and writtenregisters=(R2, R3, R4, R5, R8, shown in FIG. 12. The written registersare the live-in registers for helper thread 1003 (e.g., R2 and R3), thewritten registers in helper thread 1003 (e.g., R4 and R5) and theregisters written in helper thread 1002 (e.g., R8 and R9). Then thecompiler allocates the registers for helper thread 1004. When theregisters are allocated for all the helper threads, it allocates theregisters for the main thread 1001.

In addition, according to one embodiment, when the compiler runs out ofregisters, it can delete one or more helper threads within the chain.This can happen for example, when the main thread runs out of registers,because the helper thread chain is too deep or a single helper threadneeds too many registers and the main thread has to spill/fillregisters. The compiler can apply heuristics to either allow certainnumber of spills or delete the entire helper thread chain or somethreads in the thread chain. An alternative to deleting helper thread isto explicitly configure the weight of context save/restore, so that uponcontext switch, the parent's live registers that could be written by thehelper thread's execution can be saved automatically by the hardware.Even though this context switch is relatively expensive, potentiallysuch case is infrequent case. Moreover, such fine-grain context switchis still of much low overhead compared to full-context switch as used inmost OS-enabled thread switch or a traditional hardware basedfull-context thread switch.

Furthermore, when there is a conflict for live-in registers, forexample, if helper thread 1003 overwrote a live-in register (e.g., movv5=. . . ) and this register is also used in helper thread 1002 afterthe spawn of helper thread 1003, there would be a resource conflict forthe register assigned to v5 (in this example, register R2). To handlethis information, the compiler would use availability analysis andinsert compensation code, such as inserting a mov v5′=v5 instructionbefore spawning helper thread 1003 and replacing v5 by v5′ after thespawn.

FIG. 13 is a flow diagram illustrating an exemplary process forallocating resources for threads according to one embodiment. Exemplaryprocess 1300 may be performed by a processing logic that may comprisehardware (circuitry, dedicated logic, etc.), software (such as is run ona general purpose computer system or a dedicated machine), or acombination of both. In one embodiment, exemplary process 1300 includesselecting, during a compilation of a code having one or more threadsexecutable in a data processing system, a current thread having a mostbottom order, determining resources allocated to one or more childthreads spawned from the current thread, and allocating resources forthe current thread in consideration of the resources allocated to thecurrent thread's one or more child threads to avoid resource conflictsbetween the current thread and its one or more child threads.

Referring to FIG. 13, at block 1301, processing logic identifies one ormore threads, including a main thread and its helper threads, andselects a thread having the most bottom order as a current thread. Thethreads may be identified using a thread dependency graph created duringthe thread creation phase of the compilation. At block 1302, theprocessing logic retrieves resource information of any child thread,which may be spawned from the current thread. The resources informationmay be obtained from a data structure corresponding to the childthreads, such as resource table 1200 of FIG. 12. At block 1303, if thereis no more resources available, the processing logic may delete one ormore threads from the chain and restart over again (block 1309). Ifthere is more resource available, at block 1304, the processing logicallocates resources for the current thread in consideration of resourcesused by its child threads without causing resource conflicts.Thereafter, at block 1305, the processing logic updates the resourcesallocated to the current thread in the associated resource table, suchas resource table 1200. The above processes continue until no morehelper threads (e.g., child threads of the main thread) remained (blocks1306 and 1308). Finally, at block 1307, the processing logic allocatesresources for the main thread (e.g., a parent thread for all helperthreads) based on the resource information of all the helper threadswithout causing resource conflicts. Other operations may be included.

The above described techniques have been tested against a variety ofbenchmark tools based on a system similar to the followingconfigurations: A Processor with Hyper-Threading Technology Threading  2logical processors. Trace cache  12k micro-ops. 8-way associative.  6micro-ops per line. L1 D cache  8k bytes. 4-way associative. 64-byteline size.  2-cycle integer access. 4-cycle FP access. L2 unified 256kbytes. 8-way associative. cache 128-byte line size. 7-cycle accesslatency. Load buffers  48 Store buffers  24

The variety of benchmark tools include at least one of the following:Benchmark Description Input Set nbody_walker Traverses nearest bodies20k bodies from any node in Nbody graph mst Computes Minimal  3k nodesSpanning Tree for data clustering em3d Solves electromagnetic 20k 5-propagation in 3D degree nodes health Hierarchical database  5 levelsmodeling health care system mcf Integer programming Lite algorithm usedfor bus schedulingFIG. 14A is a chart illustrating an improvement of performance by thehelper thread on nbody_walker benchmark utility. FIG. 14B is a chartillustrating a speedup result of nbody_walker at a given value ofsynchronization period. FIG. 14C is a chart illustrating an automaticprocess versus a manual process with respect to a variety of benchmark.FIG. 14D is chart illustrating an improvement of an automatic processover a manual process using nbody_walker at a given synchronizationperiod.

Thus, methods and apparatuses for thread management for multi-threadinghave been described. In the foregoing specification, the invention hasbeen described with reference to specific exemplary embodiments thereof.It will be evident that various modifications may be made theretowithout departing from the broader spirit and scope of the invention asset forth in the following claims. The specification and drawings are,accordingly, to be regarded in an illustrative sense rather than arestrictive sense.

1. A method, comprising: selecting, during a compilation of code havingone or more threads executable in a data processing system, a currentthread having a most bottom order; determining resources allocated toone or more child threads spawned from the current thread; andallocating resources for the current thread in consideration of theresources allocated to the current thread's one or more child threads toavoid resource conflicts between the current thread and its one or morechild threads.
 2. The method of claim 1, wherein the resources includeat least one of hardware registers and memory used by the respectivethread.
 3. The method of claim 1, wherein the resources allocated to theone or more child threads are recorded in a data structure accessible bythe current thread.
 4. The method of claim 1, further comprisingupdating resource information in a data structure regarding theresources allocated to the current thread, the data structure beingaccessible by a parent thread of the current thread.
 5. The method ofclaim 1, further comprising repeating the selecting, determining, andallocating in a bottom-up order until each of the one or more threadshas been processed.
 6. The method of claim 5, further comprisingallocate resources for a main thread that is a parent thread of the oneor more threads after each of the one or more threads has beenprocessed, the resources of the main thread are allocated in view ofresources allocated to the one or more threads.
 7. The method of claim1, further comprising: determining whether there are resources remainingin the data processing system prior to the allocating the resources forthe current thread; and deleting at least one child thread of thecurrent thread; and allocating the resources for the current threadusing the resources associated with the at least one deleted childthread.
 8. A machine-readable medium having executable code to cause amachine to perform a method, the method comprising: selecting, during acompilation of code having one or more threads executable in a dataprocessing system, a current thread having a most bottom order;determining resources allocated to one or more child threads spawnedfrom the current thread; and allocating resources for the current threadin consideration of the resources allocated to the current thread's oneor more child threads to avoid resource conflicts between the currentthread and its one or more child threads.
 9. The machine-readable mediumof claim 8, wherein the resources include at least one of hardwareregisters and memory used by the respective thread.
 10. Themachine-readable medium of claim 8, wherein the resources allocated tothe one or more child threads are recorded in a data structureaccessible by the current thread.
 11. The method of claim 1, furthercomprising updating resource information in a data structure regardingthe resources allocated to the current thread, the data structure beingaccessible by a parent thread of the current thread.
 12. Themachine-readable medium of claim 8, wherein the method further comprisesrepeating the selecting, determining, and allocating in a bottom-uporder until each of the one or more threads has been processed.
 13. Themachine-readable medium of claim 12, wherein the method furthercomprises allocating resources for a main thread that is a parent threadof the one or more threads after each of the one or more threads hasbeen processed, the resources of the main thread are allocated in viewof resources allocated to the one or more threads.
 14. Themachine-readable medium of claim 8, wherein the method furthercomprises: determining whether there are resources remaining in the dataprocessing system prior to the allocating the resources for the currentthread; and deleting at least one child thread of the current thread;and allocating the resources for the current thread using the resourcesassociated with the at least one deleted child thread.
 15. A dataprocessing system, comprising: a processor capable of performingmulti-threading operations; a memory coupled to the processor; and aprocess executed by the processor from the memory to cause the processorto select, during a compilation of code having one or more threadsexecutable in a data processing system, a current thread having a mostbottom order, determine resources allocated to one or more child threadsspawned from the current thread, and allocate resources for the currentthread in consideration of the resources allocated to the currentthread's one or more child threads to avoid resource conflicts betweenthe current thread and its one or more child threads.
 16. The dataprocessing system of claim 15, wherein the process further causes theprocessor to update resource information in a data structure regardingthe resources allocated to the current thread, the data structure beingaccessible by a parent thread of the current thread.
 17. The dataprocessing system of claim 16, wherein the process further causes theprocessor to repeat the selecting, determining, and allocating in abottom-up order until each of the one or more threads has beenprocessed.
 18. The data processing system of claim 17, wherein theprocess further causes the processor to allocate resources for a mainthread that is a parent thread of the one or more threads after each ofthe one or more threads has been processed, the resources of the mainthread are allocated in view of resources allocated to the one or morethreads.
 19. The data processing system of claim 15, wherein the processfurther causes the processor to: determine whether there are resourcesremaining in the data processing system prior to the allocating theresources for the current thread; and delete at least one child threadof the current thread; and allocate the resources for the current threadusing the resources associated with the at least one deleted childthread.
 20. The data processing system of claim 15, wherein theresources include at least one of hardware registers and memory used bythe respective thread.